<?php namespace Admin\Controller;
/**
 * 管理员控制器
 */
class UserController extends CommonController
{
	/**
	 * 修改密码
	 */
	public function changePwd()
	{
		if(IS_POST)
		{
			//实例化模型
			$usermodel = new \Common\Model\Admin;
			//接收提交过来的信息
			$password = $_POST['password'];
			$newPassword = $_POST['newPassword'];
			$confirmPassword = $_POST['confirmPassword'];
			//获取当前用户的数据
			$data = $usermodel->where('admin_id',$_SESSION['admin_id'])->first();
			if($data['admin_password']!=md5($password))
			{
				$this->error('原密码错误');
			}
			if($newPassword!=$confirmPassword)
			{
				$this->error('两次新密码不一致');
			}
			$newPassword = md5($newPassword);
			//执行修改
			$usermodel->where('admin_id',$_SESSION['admin_id'])->update(array('admin_password'=>$newPassword));
			//重新登录
			session_unset();
			session_destroy();
			$this->success('密码修改成功，请重新登录','Login/index');
		}
		View::make();
	}
}
